@model List<DeathReportManagement.Models.OperationLog>
@{
    ViewData["Title"] = "操作日志";
}

<div class="d-flex justify-content-between align-items-center mb-3">
    <h2>操作日志</h2>
    <a asp-action="Statistics" class="btn btn-primary">统计分析</a>
</div>

<div class="card mb-3">
    <div class="card-header">
        <h6 class="mb-0">筛选条件</h6>
    </div>
    <div class="card-body">
        <form method="get">
            <div class="row">
                <div class="col-md-3">
                    <label for="reportId" class="form-label">报告ID</label>
                    <input type="number" class="form-control" id="reportId" name="reportId" value="@ViewBag.ReportId" />
                </div>
                <div class="col-md-3">
                    <label for="startDate" class="form-label">开始日期</label>
                    <input type="date" class="form-control" id="startDate" name="startDate" value="@ViewBag.StartDate" />
                </div>
                <div class="col-md-3">
                    <label for="endDate" class="form-label">结束日期</label>
                    <input type="date" class="form-control" id="endDate" name="endDate" value="@ViewBag.EndDate" />
                </div>
                <div class="col-md-3 d-flex align-items-end">
                    <button type="submit" class="btn btn-primary me-2">查询</button>
                    <a asp-action="Index" class="btn btn-secondary">重置</a>
                </div>
            </div>
        </form>
    </div>
</div>

@if (Model.Count == 0)
{
    <div class="alert alert-info">
        暂无操作日志数据
    </div>
}
else
{
    <div class="table-responsive">
        <table class="table table-striped table-sm">
            <thead>
                <tr>
                    <th>时间</th>
                    <th>操作</th>
                    <th>操作人</th>
                    <th>报告编号</th>
                    <th>备注</th>
                </tr>
            </thead>
            <tbody>
                @foreach (var log in Model)
                {
                    <tr>
                        <td>@log.OperateTime.ToString("yyyy-MM-dd HH:mm:ss")</td>
                        <td>
                            @switch (log.Operation)
                            {
                                case "创建死亡报告":
                                    <span class="badge bg-success">@log.Operation</span>
                                    break;
                                case "修改死亡报告":
                                    <span class="badge bg-info">@log.Operation</span>
                                    break;
                                case "审核通过":
                                    <span class="badge bg-primary">@log.Operation</span>
                                    break;
                                case "审核退回":
                                    <span class="badge bg-warning">@log.Operation</span>
                                    break;
                                case "附联上报":
                                case "自动附联上报":
                                    <span class="badge bg-secondary">@log.Operation</span>
                                    break;
                                case "主联上报":
                                    <span class="badge bg-dark">@log.Operation</span>
                                    break;
                                default:
                                    <span class="badge bg-light text-dark">@log.Operation</span>
                                    break;
                            }
                        </td>
                        <td>@log.User.Name</td>
                        <td>
                            @if (log.Report != null)
                            {
                                <a asp-controller="DeathReport" asp-action="Details" asp-route-id="@log.ReportId">
                                    @log.Report.ReportNo
                                </a>
                            }
                            else
                            {
                                <span class="text-muted">-</span>
                            }
                        </td>
                        <td>
                            @if (!string.IsNullOrEmpty(log.Remark))
                            {
                                <small class="text-muted">@log.Remark</small>
                            }
                        </td>
                    </tr>
                }
            </tbody>
        </table>
    </div>
    
    @if (Model.Count >= 1000)
    {
        <div class="alert alert-warning">
            <strong>提示：</strong>为了性能考虑，最多显示1000条记录。请使用筛选条件缩小查询范围。
        </div>
    }
}